<?php

class jadwal{
	
	// Class Constructor
	public function __construct(){
		$this->db = new DBClass();
	}
	
	public function getJadwal(){
		
		$query = "Select * from jadwal";
		$rows = $this->db->getRows($query);
		
		return $rows;
	}

	public function get_data(){
		$query = "select idadmin, username, fullname, email from admin 
			where username='".$_COOKIE['c_usr']."'";

		$rows = $this->db->getRows($query);

		return $rows[0];	
	}
	public function Tambahjadwal($data){
		
		$query ="INSERT INTO `jadwal` (`kode_jadwal`, `no_bus`, `kode_rute`, `tgl_berangkat`) VALUES ('".@$data[3]."', ".@$data[0].", ".@$data[1].", '".@$data[2]."')";

		$this->db->putRows($query);

		header('Location: jadwal.php');
	}

	
	public function editJadwal($data){
		
		$query ="SELECT * FROM jadwal WHERE kode_jadwal='".@$data."'";
		$rows = $this->db->getRows($query);

		return array_shift($rows);
	}

	public function hapusJadwal($data){
		
		$query ="DELETE FROM jadwal WHERE kode_jadwal='".@$data."'";

		$rows = $this->db->getRows($query);

		header('Location: jadwal.php');
	}

	public function PostEdit($data){
		
		$query ="UPDATE jadwal SET No_bus=".$data[0].", Kode_Rute=".$data[1].", Tgl_berangkat='".$data[2]."' WHERE kode_jadwal='".$data[3]."'";

		$this->db->putRows($query);
	}
}